﻿-- =============================================
-- Author:		<赵洪涛>
-- Create date: <2012-02-15>
-- Description:	<返回拥有指定电话号的客户数量(客户审核用)>
-- =============================================
CREATE PROCEDURE [dbo].[proc_Customer_ReptTelCount]
(
	@Tel varchar(30),
	@CusId uniqueidentifier,
	@CompanyId int
)
AS
BEGIN
	Declare @cSql nvarchar(2000)
 
	If @Tel<>''
	Begin
		Set @cSql = 'Select Count(0) As shl From Customer
		Where CompanyId='+Convert(varchar(10),@CompanyId)+' And Audit=1
		And CustomerId<>'''+Convert(varchar(60),@CusId)+''' And
		CustomerId In(Select Distinct CustomerId From ContactPerson
		 Where (officeTel='''+@Tel+''' Or hometel='''+@Tel+''' Or Mobile='''+@Tel+'''))'

		Exec(@cSql)
	End
	Else
		Select -1 As shl
--	Else
--		Select Count(0) As shl From Customer Where
--		CompanyId=@CompanyId And Audit=1 And CustomerId<>@CusId And
--		CustomerId In(Select Distinct CustomerId From [ContactPerson]
--			Where ([OfficeTel] is null) Or ([OfficeTel]='') And
--			([HomeTel] Is Null) Or ([HomeTel]='') And 
--			([Mobile] Is Null) Or ([Mobile]=''))
END